package com.app.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.TextMessage;

/**
 * Created by xinjian.hu on 18-2-12.
 */
@Service
public class ActiveConsumerService {
    @Autowired
    private JmsTemplate jmsTemplate;
    private static final Logger logger = LoggerFactory.getLogger(ActiveConsumerService.class);
    /**
     * 获取指定队列的消息
     *
     * @param destination
     * @return
     */
    public TextMessage receive(Destination destination) {
        TextMessage textMessage = (TextMessage) jmsTemplate.receive(destination);
        try {
            logger.info("从队列{}====>收到了消息{}",destination.toString(),textMessage.getText());
            System.out.println();
        } catch (JMSException e) {
            e.printStackTrace();
        }
        return textMessage;
    }
}
